package com.kerbores.agent.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.net.Socket;

import org.nutz.lang.Strings;
import org.nutz.net.SocketHandler;
import org.nutz.net.TcpServer;

public class Server {

	public static void main(String[] args) {
		TcpServer server = new TcpServer(9999, new SocketHandler() {

			@Override
			public void whenError(Socket paramSocket, Throwable paramThrowable) {
				// TODO Auto-generated method stub

			}

			@Override
			public void handle(Socket socket) throws IOException {
				BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				Writer bw = new java.io.OutputStreamWriter(socket.getOutputStream());
				String line;
				while (!Strings.isBlank((line = br.readLine()))) {
					String re = handleLine(line);
					if (!org.nutz.lang.Strings.isBlank(re)) {
						bw.write(re);
						bw.flush();
					}
				}
			}

			private String handleLine(String line) {
				return line;
			}
		});
		server.run();
	}
}
